﻿<UserControl x:Class="Supremacy.Client.Views.ColonyStructureListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:s="http://schemas.startreksupremacy.com/xaml/core"
             xmlns:scc="http://schemas.startreksupremacy.com/xaml/presentation">
  
  <ItemsControl Grid.IsSharedSizeScope="True"
                Focusable="False"
                IsTabStop="False"
                ItemsSource="{Binding Path=SelectedColony.Buildings}">
    <ItemsControl.Resources>
      <DataTemplate x:Key="StructureListItemTemplate">
        <Border Padding="7"
                scc:InfoCardService.InfoCardHeader="{Binding RelativeSource={RelativeSource Self}, Path=(scc:InfoCardService.InfoCardSubject).(scc:InfoCardSubject.Data), Mode=OneWay}"
                scc:InfoCardService.InfoCardContent="{Binding RelativeSource={RelativeSource Self}, Path=(scc:InfoCardService.InfoCardSubject).(scc:InfoCardSubject.Data), Mode=OneWay}">
          <scc:InfoCardService.InfoCardHeaderTemplate>
            <DataTemplate DataType="{x:Type s:Building}">
              <DockPanel LastChildFill="True">
                <Border DockPanel.Dock="Left"
                        VerticalAlignment="Top"
                        CornerRadius="4"
                        Margin="0,0,6,0"
                        Width="58"
                        Height="48"
                        Background="Black">
                  <Border x:Name="ImageBorder"
                          BorderBrush="White"
                          BorderThickness="2"
                          CornerRadius="4">
                    <Border.Background>
                      <ImageBrush ImageSource="{Binding Path=(s:TechObject.Design).(s:TechObjectDesign.Image), Converter={StaticResource TechObjectImageConverter}}" />
                    </Border.Background>
                  </Border>
                </Border>
                <StackPanel Orientation="Vertical"
                            TextBlock.FontSize="{DynamicResource {x:Static scc:ClientResources.DefaultFontSizeKey}}"
                            TextBlock.FontFamily="{DynamicResource {x:Static scc:ClientResources.DefaultFontFamilyKey}}"
                            TextBlock.Foreground="{DynamicResource {x:Static scc:ClientResources.DefaultTextForegroundBrushKey}}">
                  <TextBlock Text="{Binding Path=BuildingDesign.Name}"
                             FontSize="{DynamicResource {x:Static scc:ClientResources.HeaderFontSizeKey}}"
                             FontWeight="{DynamicResource {x:Static scc:ClientResources.HeaderFontWeightKey}}"
                             Foreground="{DynamicResource {x:Static scc:ClientResources.HeaderTextForegroundBrushKey}}" />
                  <TextBlock x:Name="AgeText"
                             Text="{Binding Path=Age, Mode=OneWay, StringFormat='{}Constructed {0} turns ago'}" />
                  <WrapPanel>
                    <TextBlock Text="Status: " />
                    <TextBlock x:Name="StatusText"
                               Text="Online"
                               Foreground="LimeGreen" />
                  </WrapPanel>
                  <scc:GameButton Label="{s:StringResource Scrap}"
                                  Margin="0,5,0,0"
                                  DisplayMode="CheckBox"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  Command="{x:Static scc:ColonyScreenCommands.ToggleBuildingScrapCommand}">
                    <scc:GameButton.CommandParameter>
                      <scc:CheckableCommandParameter InnerParameter="{Binding Mode=OneWay}" />
                    </scc:GameButton.CommandParameter>
                  </scc:GameButton>
                </StackPanel>
              </DockPanel>
              <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=IsActive}"
                             Value="False">
                  <Setter TargetName="StatusText"
                          Property="Text"
                          Value="Offline" />
                  <Setter TargetName="StatusText"
                          Property="Foreground"
                          Value="Crimson" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Age}"
                             Value="1">
                  <Setter TargetName="AgeText"
                          Property="Text"
                          Value="Constructed last turn" />
                </DataTrigger>
              </DataTemplate.Triggers>
            </DataTemplate>
          </scc:InfoCardService.InfoCardHeaderTemplate>
          <scc:InfoCardService.InfoCardContentTemplate>
            <DataTemplate DataType="{x:Type s:Building}">
              <TabControl Margin="-5">
                <TabItem Header="Specifications">
                  <ContentControl Style="{DynamicResource TechObjectInfoPanelStyle}">
                    <scc:TechObjectDesignViewModel Design="{Binding Path=(s:Building.BuildingDesign)}"
                                                   Location="{Binding Path=(s:Building.BuildingDesign).(s:UniverseObject.Location)}"
                                                   Civilization="{Binding Path=(s:Building.BuildingDesign).(s:UniverseObject.Owner)}" />
                  </ContentControl>
                </TabItem>
                <TabItem Header="Description">
                  <DockPanel LastChildFill="True">
                    <TextBlock DockPanel.Dock="Top"
                               TextWrapping="Wrap"
                               FontFamily="{DynamicResource {x:Static scc:ClientResources.HeaderFontFamilyKey}}"
                               FontSize="{DynamicResource {x:Static scc:ClientResources.HeaderFontSizeKey}}"
                               FontWeight="{DynamicResource {x:Static scc:ClientResources.HeaderFontWeightKey}}"
                               Text="{Binding Path=(s:Building.BuildingDesign).(s:TechObjectDesign.Name)}" />
                    <TextBlock TextWrapping="Wrap"
                               Margin="0,11,0,0"
                               FontFamily="{DynamicResource {x:Static scc:ClientResources.DefaultFontFamilyKey}}"
                               FontSize="{DynamicResource {x:Static scc:ClientResources.DefaultFontSizeKey}}"
                               FontWeight="{DynamicResource {x:Static scc:ClientResources.DefaultFontWeightKey}}"
                               Text="{Binding Path=(s:Building.BuildingDesign).(s:TechObjectDesign.Description)}" />
                  </DockPanel>
                </TabItem>
              </TabControl>
            </DataTemplate>
          </scc:InfoCardService.InfoCardContentTemplate>
          <scc:InfoCardService.InfoCardSubject>
            <scc:UniverseObjectInfoCardSubject Target="{Binding Mode=OneTime}" />
          </scc:InfoCardService.InfoCardSubject>
          <Button x:Name="ActivateButton"
                  Command="{Binding Path=Model.ToggleBuildingIsActiveCommand, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type scc:ColonyScreenView}}}"
                  CommandParameter="{Binding}"
                  Focusable="False"
                  ContextMenuService.ShowOnDisabled="True"
                  Style="{StaticResource LCARS_BaseButtonStyle}">
            <Button.Template>
              <ControlTemplate TargetType="{x:Type Button}">
                <ContentPresenter />
              </ControlTemplate>
            </Button.Template>
            <Button.ContextMenu>
              <ContextMenu>
                <MenuItem Header="{s:StringResource Scrap}"
                          IsCheckable="True"
                          IsChecked="{Binding Path=Scrap, Mode=OneWay}"
                          Command="{x:Static scc:ColonyScreenCommands.ToggleBuildingScrapCommand}"
                          CommandParameter="{Binding}" />
              </ContextMenu>
            </Button.ContextMenu>
            <Grid>
              <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="StructureListItem_ImageColumn" />
                <ColumnDefinition SharedSizeGroup="StructureListItem_TextColumn" />
              </Grid.ColumnDefinitions>
              <Grid.RowDefinitions>
                <RowDefinition SharedSizeGroup="StructureListItem_Row" />
              </Grid.RowDefinitions>
              <Border x:Name="ImageBorder"
                      Grid.Column="0"
                      VerticalAlignment="Center"
                      BorderBrush="White"
                      BorderThickness="2"
                      CornerRadius="4"
                      Width="58"
                      Height="48">
                <Border.Background>
                  <ImageBrush ImageSource="{Binding Path=(s:TechObject.Design).Image, Converter={StaticResource TechObjectImageConverter}}" />
                </Border.Background>
              </Border>
              <StackPanel Grid.Column="1"
                          Orientation="Vertical"
                          VerticalAlignment="Center"
                          HorizontalAlignment="Stretch"
                          Margin="7,0,7,0"
                          TextBlock.FontFamily="{StaticResource LCARS_ParagraphFont}">
                <TextBlock FontSize="14pt">
                  <TextBlock Foreground="{StaticResource LCARS_BlueTextBrush}"
                             Text="{Binding Path=(s:TechObject.Design).Name, Converter={StaticResource StringResourceConverter}}" />
                  <TextBlock x:Name="ScrapText"
                             Foreground="Crimson"
                             Text="(SCRAP)"
                             Opacity="0.0" />
                </TextBlock>
                <TextBlock Foreground="{StaticResource LCARS_BeigeTextBrush}"
                           FontSize="11pt"
                           TextWrapping="NoWrap"
                           TextTrimming="CharacterEllipsis">
                  <TextBlock x:Name="EnergyCostText">
                    <TextBlock Text="{Binding Path=(s:Building.BuildingDesign).EnergyCost}" />
                    <TextBlock Text="Energy Cost," />
                  </TextBlock>
                  <TextBlock Text="{Binding Path=Design, Converter={StaticResource BonusConverter}, ConverterParameter=CommaSeparated}" />
                </TextBlock>
              </StackPanel>
            </Grid>
          </Button>
        </Border>
        <DataTemplate.Triggers>
          <DataTrigger Binding="{Binding Path=IsActive}"
                       Value="False">
            <Setter TargetName="ImageBorder"
                    Property="Opacity"
                    Value="0.25" />
          </DataTrigger>
          <DataTrigger Binding="{Binding Path=Scrap}"
                       Value="True">
            <Setter TargetName="ScrapText"
                    Property="Opacity"
                    Value="1.0" />
          </DataTrigger>
          <DataTrigger Binding="{Binding Path=Design.AlwaysOnline}"
                       Value="True">
            <Setter TargetName="EnergyCostText"
                    Property="Visibility"
                    Value="Collapsed" />
          </DataTrigger>
        </DataTemplate.Triggers>
      </DataTemplate>
    </ItemsControl.Resources>
    <ItemsControl.Template>
      <ControlTemplate TargetType="{x:Type ItemsControl}">
        <ScrollViewer CanContentScroll="True"
                      VerticalScrollBarVisibility="Visible"
                      HorizontalScrollBarVisibility="Disabled">
          <WrapPanel Orientation="Horizontal"
                     IsItemsHost="True" />
        </ScrollViewer>
      </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemTemplate>
      <StaticResource ResourceKey="StructureListItemTemplate" />
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</UserControl>
